package com.rongxue.controller.payment;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.rongxue.mapper.SProjectMapper;
import com.rongxue.mapper.SUserDueDetailMapper;
import com.rongxue.mapper.SUserMapper;
import com.rongxue.mapper.SUserWalletRecordsMapper;
import com.rongxue.pojo.*;
import com.rongxue.service.CashInAndOutService;
import com.rongxue.service.Impl.CashInAndOutServiceImpl;
import com.rongxue.service.ProjectService;
import com.rongxue.service.shanbei.services.AccountService;
import com.rongxue.service.shanbei.util.ConfigUtil;
import com.rongxue.service.shanbei.util.SignUtil;
import com.rongxue.service.utils.P2PMessageUtils;
import com.rongxue.utils.CommonUtils;
import com.rongxue.utils.DateUtil;
import com.rongxue.utils.Page;
import org.apache.commons.lang3.StringEscapeUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.*;
import java.math.BigDecimal;
import java.net.URL;
import java.net.URLConnection;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static java.math.BigDecimal.ROUND_HALF_DOWN;


@Controller
public class ProjectController {

    @Autowired
    private ProjectService projectService;

    @Autowired
    private HttpServletRequest request;
    @Autowired
    HttpServletResponse response;

    @Autowired
    private SProjectMapper sProjectMapper;
    @Autowired
    private SUserMapper sUserMapper;
    @Autowired
    private SUserWalletRecordsMapper sUserWalletRecordsMapper;
    @Autowired
    private SUserDueDetailMapper sUserDueDetailMapper;

    private static final Logger logger = LoggerFactory.getLogger(ProjectController.class);

    //用户投资
    @ResponseBody
    @RequestMapping(value = "/tender/tender", method = RequestMethod.POST, produces = "application/json")
    public ObjectResult tender(XMLBean xmlBean){

           logger.info("參數：" + xmlBean);
        //传输参数
        if (xmlBean.getToken() == null || xmlBean.getToken().equals("") || xmlBean.getAmoney() == null || xmlBean.getAmoney().equals("") || xmlBean.getDevice_type() == null
                || xmlBean.getDevice_type().toString().equals("") || xmlBean.getProject_id() == null || xmlBean.getProject_id().equals("") || xmlBean.getMoney() == null
                || xmlBean.getMoney().equals("") || xmlBean.getPay_type() == null || xmlBean.getPay_type().equals("")){

            return ObjectResult.build("0", "参数丢失,请重试");
        }
        BigDecimal amoney = new BigDecimal(xmlBean.getAmoney());
        BigDecimal[] results = amoney.divideAndRemainder(BigDecimal.valueOf(100));
        if (results[1] != BigDecimal.valueOf(0)){
            return ObjectResult.build("0", "投资金额必须是100的整数");
        }
        ObjectResult result = projectService.tender(xmlBean);
        return result;
    }


    //投资回调
    @ResponseBody
    @RequestMapping(value = "tender/tenderNotify", method = RequestMethod.POST, produces = "application/json")
    public void tenderNotify() throws Exception {
        Map<String, Object> map = P2PMessageUtils.sign(request, "投资回调报文：");
        if (!(Boolean)map.get("flag"))return;

        ObjectResult ObjectResult = projectService.verificationTenderNotify((JSONObject) map.get("jsonObject"));

        if (ObjectResult.getCode().equals("0")){
            logger.info("msg:"+ObjectResult.getStr());
            return;
        }
        //返回回成功
        PrintWriter pw = null;
        try {
            pw = response.getWriter();
            pw.write("success");
            pw.flush();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            pw.close();
        }

    }


    /**
     * 还款
     * @param xmlBean
     * @return
     */
    @RequestMapping(value = "/project/repayment", method = RequestMethod.POST, produces = "application/json")
    @ResponseBody
    public ObjectResult repayment(XMLBean xmlBean) {
        if (xmlBean.getToken()==null || xmlBean.getToken().equals("") || xmlBean.getId()==null || xmlBean.getId().equals("")){
            ObjectResult.build("0","参数丢失请重试");
        }
       return   projectService.repayment(xmlBean);
    }


    /**
     * 还款回调
     * @return
     */
    @RequestMapping(value = "/project/repaymentNotify", method = RequestMethod.POST, produces = "application/json")
    @ResponseBody
    public void loanNotify() throws Exception {
        Map<String, Object> map = P2PMessageUtils.sign(request, "还款回调报文：");
        JSONObject jsonObject = (JSONObject) map.get("jsonObject");
        if (!(Boolean)map.get("flag")){
            //回调失败状态回到待还款
            SUserWalletRecords sUserWalletRecords = sUserWalletRecordsMapper.selectWalletRecordsByrRechargeNo(jsonObject.getString("batch_no"));
            sUserWalletRecords.setPayStatus(1);
            sUserWalletRecordsMapper.updateByPrimaryKeySelective(sUserWalletRecords);
            return;
        }

        List<Map<String, String>> list = (List<Map<String, String>>) jsonObject.get("items");


        ObjectResult ObjectResult = projectService.loanNotify(list,jsonObject.getString("batch_no"));

        if (ObjectResult.getCode().equals("0")){
            logger.info("msg:"+ObjectResult.getStr());
            return;
        }
        //返回回成功
        PrintWriter pw = null;
        try {
            pw = response.getWriter();
            pw.write("success");
            pw.flush();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            pw.close();
        }
    }

    /**
     * 还款撤销
     * @throws Exception
     */
    @RequestMapping(value = "/project/batchRevokeRepayment", method = RequestMethod.POST, produces = "application/json")
    @ResponseBody
    public ObjectResult batchRevokeRepayment(XMLBean xmlBean) {
       return  projectService.batchRevokeRepayment(xmlBean);
    }

    /**
     * 还款结果查询
     * @param xmlBean
     * @return
     */
    @RequestMapping(value = "/project/selectLoan")
    @ResponseBody
    public ObjectResult selectLoan(XMLBean xmlBean) {

        String str = null;
        Map<String, Object> reqMap = new HashMap<String, Object>();
        reqMap.put("service", "batch_new_query_repayment_b");
        reqMap.put("batch_no", xmlBean.getTitle());
        reqMap.put("timestamp", String.valueOf(new Date().getTime() / 1000));
        reqMap.put("uuid", "" + System.currentTimeMillis() / 100);
        reqMap.put("sign_type", "");
        reqMap.put("encode", "UTF-8");
        reqMap.put("version", "2.0.0");
        reqMap.put("custom", "");
        reqMap.put("client", "000001");
        reqMap.put("client_ip", "47.98.107.188");
        reqMap.put("client_service", "00:16:3e:11:b0:02");
        String rft_key = ConfigUtil.getPro("bank.key");
        String rft_secret = ConfigUtil.getPro("bank.secret");
        str = AccountService.createAccount(reqMap, rft_key, rft_secret);
        JSONObject jsonObject = JSONObject.parseObject(str);
       return ObjectResult.build("1","",jsonObject);
    }




    /**
     * 借款人还款金额签约查询
     * @param xmlBean
     * @return
     */
    @RequestMapping(value ="/project/signRepaymentQuery")
    @ResponseBody
    public ObjectResult signRepaymentQuery(XMLBean xmlBean){
        String userId =xmlBean.getId();
        SUser sUser = sUserMapper.selectByPrimaryKey(Long.parseLong(userId));
        if(sUser.getType()!=2){
            ObjectResult.build("0","非借款用户");
        }
        String str = null;
        Map<String, Object> reqMap = new HashMap<String, Object>();
        reqMap.put("service", "sign_repayment_query");
        reqMap.put("card_no", sUser.getCard_no2());
        reqMap.put("timestamp", String.valueOf(new Date().getTime() / 1000));
        reqMap.put("uuid", "" + System.currentTimeMillis() / 100);
        reqMap.put("sign_type", "");
        reqMap.put("encode", "UTF-8");
        reqMap.put("version", "2.0.0");
        reqMap.put("custom", "");
        reqMap.put("client", "000001");
        reqMap.put("client_ip", "47.98.107.188");
        reqMap.put("client_service", "00:16:3e:11:b0:02");
        String rft_key = ConfigUtil.getPro("bank.key");
        String rft_secret = ConfigUtil.getPro("bank.secret");
        str = AccountService.createAccount(reqMap, rft_key, rft_secret);
        JSONObject jsonObject = JSONObject.parseObject(str);

        if (jsonObject.getString("code").equals("RD000000")){
            return ObjectResult.build("1","",jsonObject);
        }else {
            return ObjectResult.build("0",jsonObject.getString("msg"));
        }
    }


    /**
     * 产品列表
     * @param xmlBean
     * @return
     */
    @RequestMapping(value = "/project/project_list", method = RequestMethod.POST, produces = "application/json")
    @ResponseBody
    public ObjectResult project_list(XMLBean xmlBean) {
        Map<String,Object> data = new HashMap<String,Object>();
        try {
            List<SProject> list = sProjectMapper.selectProjectListByStatus();
//            Page<SProject> page = new Page<>();
//            page.setP(xmlBean.getP());
//            page.setPageSize(10);
//            List<SProject> content = page.getPageContent(list);
            List<SProject> list2 = new ArrayList<>();
            List<SProject> list3 = new ArrayList<>();
            List<SProject> list5 = new ArrayList<>();
            int count = 0;
            for (SProject sProject:list){
//                sProject.setDuration(DateUtil.getDaysBetweenToDate(sProject.getEndTime(),new Date()));
                if (sProject.getStatus()==2){
                    list2.add(sProject);
                }
                if (sProject.getStatus()==3 || sProject.getStatus()==6 || sProject.getStatus()==5){
                    if (count<=1) {
                        list3.add(sProject);
                        count++;
                    }
                }
            }
            data.put("list2",list2);
            data.put("list3",list3);
            data.put("list5",list5);
//            data.put("count",page.getPageTotal());
            return  ObjectResult.build("1","成功",data);
        }catch (Exception e){
            e.printStackTrace();
            return  ObjectResult.build("0","失败");
        }

    }


    /**
     * 产品列表
     * @param xmlBean
     * @return
     */
    @RequestMapping(value = "/project/project_list2", method = RequestMethod.POST, produces = "application/json")
    @ResponseBody
    public ObjectResult project_list2(XMLBean xmlBean) {
        Map<String,Object> data = new HashMap<String,Object>();
        try {
            List<SProject> list = sProjectMapper.selectProjectListByStatus();
//            Page<SProject> page = new Page<>();
//            page.setP(xmlBean.getP());
//            page.setPageSize(10);
//            List<SProject> content = page.getPageContent(list);
            List<SProject> list2 = new ArrayList<>();
            List<SProject> list3 = new ArrayList<>();
            List<SProject> list5 = new ArrayList<>();

//            Integer count = 0;
            for (SProject sProject:list){
//                sProject.setDuration(DateUtil.getDaysBetweenToDate(sProject.getEndTime(),new Date()));
                if (sProject.getStatus()==2){
                    list2.add(sProject);
                }
//                if (sProject.getStatus()==3 || sProject.getStatus()==6 || sProject.getStatus()==5){
//                    if (xmlBean.getType()!=null&&xmlBean.getType()==1&&count>1) {
//
//                    }else {
//                        list3.add(sProject);
//                        count++;
//                    }
//                }
            }
            Map<String,Object> map1 = new HashMap<>();
            Map<String,Object> map2 = new HashMap<>();

            map1.put("list",list2);
            map2.put("list",list3);
            Object[] array = {map1,map2};
            return  ObjectResult.build("1","成功",array);
        }catch (Exception e){
            e.printStackTrace();
            return  ObjectResult.build("0","失败");
        }
    }


    /**
     * 产品列表
     * @param xmlBean
     * @return
     */
    @RequestMapping(value = "/project/project_list3", method = RequestMethod.POST, produces = "application/json")
    @ResponseBody
    public ObjectResult project_list3(XMLBean xmlBean) {
        Map<String,Object> data = new HashMap<String,Object>();
        try {
            List<SProject> list = sProjectMapper.selectProjectListByStatus2(xmlBean.getStatus());
            if(xmlBean.getStatus()==3){
                List<SProject> list1 = sProjectMapper.selectProjectListByStatus2(6);
                for (SProject sProject:list1){
                    list.add(sProject);
                }
            }

            if(xmlBean.getStatus()==5){
                List<SProject> list1 = sProjectMapper.selectProjectListByStatus2(8);
                for (SProject sProject:list1){
                    list.add(sProject);
                }
            }

            Page<SProject> page = new Page<>();
            page.setP(xmlBean.getP());
            page.setPageSize(10);
            List<SProject> content = page.getPageContent(list);
            for (SProject sProject:content){
                sProject.setIdcard(sProject.getIdcard().substring(0,1)+"*****************");
                sProject.setRealName(sProject.getRealName().substring(0,1)+"**");
            }
            data.put("list",content);
            data.put("count",page.getPageTotal());
            return  ObjectResult.build("1","成功",data);
        }catch (Exception e){
            e.printStackTrace();
            return  ObjectResult.build("0","失败");
        }
    }



    public static String getTextFromTHML(String htmlStr) {
        Document doc = Jsoup.parse(htmlStr);
        String text = doc.text();
        // remove extra white space
        StringBuilder builder = new StringBuilder(text);
        int index = 0;
        while(builder.length()>index){
            char tmp = builder.charAt(index);
            if(Character.isSpaceChar(tmp) || Character.isWhitespace(tmp)){
                builder.setCharAt(index, ' ');
            }
            index++;
        }
        text = builder.toString().replaceAll(" +", " ").trim();
        return text;
    }

    /**
     * 产品详情
     * @param xmlBean
     * @return
     */
    @RequestMapping(value = "/project/project_detail", method = RequestMethod.POST, produces = "application/json")
    @ResponseBody
    public ObjectResult project_detail(XMLBean xmlBean) {

        if (xmlBean.getId()==null || xmlBean.getId().equals("")){
            return ObjectResult.build("0","参数丢失请重试");
        }

        Map<String,Object> map = new HashMap<>();

        SProject data = projectService.selectProjectByPid(xmlBean.getId());
        data.setInterest_accrual_time(DateUtil.formatDate(DateUtil.addDateDay(DateUtil.parseDate(data.getStart_time()),1)));
        BigDecimal decimal = data.getAmount().multiply(data.getUser_interest().divide(new BigDecimal(100))).multiply(new BigDecimal(data.getDuration())).divide(new BigDecimal(365),2,ROUND_HALF_DOWN);
//        data.setDuration(DateUtil.getDaysBetweenToDate(data.getEndTime(),new Date()));
        data.setTotal_revenue(decimal);
        data.setPeriods(data.getTitle().substring(data.getTitle().lastIndexOf("】")+1));//截取期数

        SUserDueDetail sUserDueDetail = sUserDueDetailMapper.selectInvestmentMax(xmlBean.getId());

        if (data.getRepaymentType()==1){
//            data.setSource("即每月偿还出借人同等数额的还款金额(包括本金和利息),具体来说，借款人每月偿还的本金比重逐月递增，利息比重逐月递减。");
            data.setSource("到期一次还本付息是指借款人在贷款期内不是按月偿还本息,而是贷款到期后一次性归还本金和利息。");
            data.setPayType("到期还本付息");
        }else {
            data.setPayType("每月付息,到期还本");
            data.setSource("即每月偿还出借人同等数额的还款利息，到了出借期限还清剩余利息和本金。");
        }
        if(sUserDueDetail==null){
            data.setTycoon("抢先成为本项目投资额最高的土豪,将有机会获得"+data.getTycoon_value()+"元土豪红包！");
        }else {
            data.setTycoon("恭喜"+ CommonUtils.concealMobile(sUserDueDetail.getMobile())+"用户抢先成为本项目投资额最高的土豪，累计投资高达"+sUserDueDetail.getDue_capital()+"元;他将有机会获得"+data.getTycoon_value()+"元土豪红包，超过他，红包就是您的！");//土豪奖
        }
        data.setLast("最后一位投资的用户将获得"+data.getLast_valiu()+"元收官红包，本项目剩余可投金额"+data.getAble()+"元，蓄势待发，红包等你拿！");//收官奖
        data.setInvest_direction(getTextFromTHML(StringEscapeUtils.unescapeHtml4(data.getInvest_direction())));
        data.setIsHide(1);
//        map.put("tycoon","恭喜157****486用户抢先成为本项目投资额最高的土豪，累计投资高达5215.00元;他将有机会获得20元土豪红包，超过他，红包就是您的！");
//        map.put("last","最后一位投资的用户将获得30元收官红包，本项目剩余可投金额30000.00元，蓄势待发，红包等你拿！");
//        map.put("list",data);
//
//        SUser sUser = sUserMapper.selectByPrimaryKey(Long.parseLong(data.getUserId()));
//        String str = null;
//        Map<String, Object> reqMap = new HashMap<String, Object>();
//        reqMap.put("service", "debt_query");
//        reqMap.put("card_no",sUser.getCard_no2());
//        reqMap.put("asset_no", xmlBean.getId());
//        reqMap.put("timestamp", String.valueOf(new Date().getTime() / 1000));
//        reqMap.put("uuid", "" + System.currentTimeMillis() / 100);
//        reqMap.put("sign_type", "MD5");
//        reqMap.put("encode", "UTF-8");
//        reqMap.put("version", "2.0.0");
//        reqMap.put("custom", "");
//        reqMap.put("client", "000001");
//        String rft_key = ConfigUtil.getPro("bank.key");
//        String rft_secret = ConfigUtil.getPro("bank.secret");
//        str = AccountService.createAccount(reqMap, rft_key, rft_secret);



        return  ObjectResult.build("1","成功",data);
    }

    @RequestMapping(value = "/project/project_details", method = RequestMethod.POST, produces = "application/json")
    @ResponseBody
    public ObjectResult project_details(XMLBean xmlBean) throws IOException {
        SProjectWithBLOBs sProject = sProjectMapper.selectProjectDetailByPid(xmlBean.getId());

        List<Map<String,Object>> list = new ArrayList<>();

        String[] split = sProject.getImage().split("src");
        for (int i =0;i<split.length-1;i++){
            Map<String,Object> map = new HashMap<>();
            if(split[i+1].contains("http")&split[i+1].contains("jpg")){
                map.put("src",split[i+1].substring(split[i+1].lastIndexOf("http"), split[i+1].lastIndexOf(".jpg") + 4));
            }
            else if(split[i+1].contains("http")&split[i+1].contains("png")){
                map.put("src",split[i+1].substring(split[i+1].lastIndexOf("http"), split[i+1].lastIndexOf(".png") + 4));
            }else {
                map.put("src","");
            }

            sProject.setFinancing(sProject.getFinancing().substring(0,2)+"********");
            sProject.setIdcard(sProject.getIdcard().substring(0,6)+"************");


//            if(!map.get("src").equals("")) {
//                //获取图片高度
//                URL url = new URL(map.get("src").toString());
//                URLConnection urlConnection = url.openConnection();
//                int length = urlConnection.getContentLength();
//                if (length == -1) {
//                    map.put("img_heigh","0");
//                } else {
//                    BufferedImage sourceImg = ImageIO.read(url);
//                    map.put("img_heigh",sourceImg.getHeight() + "");
//                }
//            }
//            else {
//                map.put("img_heigh","0");
//            }
            list.add(map);
        }

        SUser user = sUserMapper.selectByPrimaryKey(Long.parseLong(sProject.getUserId()));
        sProject.setImgList(list);
        sProject.setRegMoney(user.getRegMoney());
        sProject.setRepresent(user.getRepresent());
        sProject.setExpire(user.getExpire());
        sProject.setArea(user.getArea());
        sProject.setCategory(user.getCategory());
        sProject.setInvest_direction(getTextFromTHML(StringEscapeUtils.unescapeHtml4(sProject.getInvest_direction())));

        if (sProject.getRepaymentType()==1){
//            data.setSource("即每月偿还出借人同等数额的还款金额(包括本金和利息),具体来说，借款人每月偿还的本金比重逐月递增，利息比重逐月递减。");
            sProject.setSource("到期一次还本付息是指借款人在贷款期内不是按月偿还本息,而是贷款到期后一次性归还本金和利息。");
            sProject.setPayType("到期还本付息");
        }else {
            sProject.setPayType("每月付息,到期还本");
            sProject.setSource("即每月偿还出借人同等数额的还款利息，到了出借期限还清剩余利息和本金。");
        }


        return  ObjectResult.build("1","成功",sProject);
    }
    /**
     * 项目资料详情
     * @param xmlBean
     * @return
     */
    @RequestMapping(value = "/project/particulars")
    public ModelAndView particulars(XMLBean xmlBean) {
        SProject project = sProjectMapper.selectProjectAllById(xmlBean.getId());
        String projectDetail = project.getProjectDetail();
        ModelAndView modelAndView = new ModelAndView("msg");
        modelAndView.addObject("msg", StringEscapeUtils.unescapeHtml4(projectDetail));
        return modelAndView;
    }

    /**
     * 资金保障页面
     * @param xmlBean
     */
    @RequestMapping(value = "/project/fund_guarantee")
    public ModelAndView fund_guarantee(XMLBean xmlBean) {
        SProject project = sProjectMapper.selectProjectAllById(xmlBean.getId());
        String investPriceBao = project.getInvestPriceBao();
        ModelAndView modelAndView = new ModelAndView("msg");
        modelAndView.addObject("msg", StringEscapeUtils.unescapeHtml4(investPriceBao));
        return modelAndView;
    }

    /**
     * 产品投资列表
     * @param xmlBean
     * @return
     */
    @RequestMapping(value = "/project/invest_list")
    @ResponseBody
    public ObjectResult invest_list(XMLBean xmlBean) {
        Map<String,Object> map = new HashMap<String,Object>();
        Map<String,Object> data = new HashMap<String,Object>();
        BigDecimal total_money = new BigDecimal(0);
        List<SProject> list = projectService.selectProjectInvestList(xmlBean.getId());
//        Page<SProject> page = new Page<>();
//        page.setP(xmlBean.getP());
//        page.setPageSize(10);
//        List<SProject> content = page.getPageContent(list);
        for (SProject sProject :list){
            total_money = sProject.getAmount().add(total_money);
            sProject.setAdd_time(sProject.getAdd_time().substring(0,sProject.getAdd_time().lastIndexOf(".")));
        }

        data.put("list",list);
//        data.put("headcount",page.getRecordTotal());
//        data.put("count",page.getPageTotal());
        data.put("total_money",total_money);

        return  ObjectResult.build("1","成功",data);
    }

    /**
     * 排行榜
     * @param xmlBean
     * @return
     */
    @RequestMapping(value = "/project/rank", method = RequestMethod.POST, produces = "application/json")
    @ResponseBody
    public ObjectResult rank(XMLBean xmlBean) {
        return projectService.rank(xmlBean);
    }


    /**
     * 借款信息
     * @param xmlBean
     * @return
     */
    @RequestMapping("/project/borrowerFunds")
    @ResponseBody
    public ObjectResult borrowerFunds(XMLBean xmlBean)  {
        if(xmlBean.getToken()==null||xmlBean.getToken().equals(""))  return ObjectResult.build("0","未登录");
        return projectService.borrowerFunds(xmlBean);
    }

    /**
     * 借款人还款记录
     * @param xmlBean
     * @return
     */
    @RequestMapping("/project/repaymentRecord")
    @ResponseBody
    public ObjectResult repaymentRecord(XMLBean xmlBean)  {
//        if(xmlBean.getToken()==null||xmlBean.getToken().equals(""))  return ObjectResult.build("0","未登录");
//        String userId = CommonUtils.decToken(xmlBean.getToken());
//        List<SUserWalletRecords> sUserWalletRecords = sUserWalletRecordsMapper.selectRepaymentRecord(userId);
//        Page<SUserWalletRecords> page = new Page<>();
//        page.setP(xmlBean.getP()==null? 1:xmlBean.getP());
//        page.setPageSize(10);
//        List<SUserWalletRecords> content = page.getPageContent(sUserWalletRecords);
//
//        Map<String,Object> map = new HashMap<String,Object>();
//        map.put("list",content);
//        map.put("count",page.getPageTotal());
//
//        return ObjectResult.build("1","成功",map);
        return null;
    }


    /**
     * 借款人放款记录
     * @param xmlBean
     * @return
     */
    @RequestMapping("/project/loanRecord")
    @ResponseBody
    public ObjectResult loanRecord(XMLBean xmlBean)  {
        if(xmlBean.getToken()==null||xmlBean.getToken().equals(""))  return ObjectResult.build("0","未登录");
        String userId = CommonUtils.decToken(xmlBean.getToken());
//        List<SUserWalletRecords> sUserWalletRecords = sUserWalletRecordsMapper.selectLoanRecord(userId);
//        Page<SUserWalletRecords> page = new Page<>();
//        page.setP(xmlBean.getP()==null? 1:xmlBean.getP());
//        page.setPageSize(10);
//        List<SUserWalletRecords> content = page.getPageContent(sUserWalletRecords);
//
//        Map<String,Object> map = new HashMap<String,Object>();
//        map.put("list",content);
//        map.put("count",page.getPageTotal());

//        return ObjectResult.build("1","成功",map);

        return null;
    }

    @RequestMapping(value = "/aaa")
    @ResponseBody
    public ObjectResult aaa() {
        SUser sUser = sUserMapper.selectByPrimaryKey(42l);

        String str = null;
        Map<String, Object> reqMap = new HashMap<String, Object>();
        reqMap.put("service", "apply_bid_query");
        reqMap.put("card_no",sUser.getCard_no2());
        reqMap.put("out_serial_no","B103711498675701286300050");
        reqMap.put("timestamp", String.valueOf(new Date().getTime() / 1000));
        reqMap.put("uuid", "" + System.currentTimeMillis() / 100);
        reqMap.put("sign_type", "");
        reqMap.put("encode", "UTF-8");
        reqMap.put("version", "2.0.0");
        reqMap.put("custom", "");
        reqMap.put("client", "000002");
        String rft_key = ConfigUtil.getPro("bank.key");
        String rft_secret = ConfigUtil.getPro("bank.secret");
        str = AccountService.createAccount(reqMap, rft_key, rft_secret);
        JSONObject jsonObject = JSONObject.parseObject(str);

        return ObjectResult.build("1","cg",jsonObject);
    }

}
